package com.jessechanrui.template.flowable.flowabletemplate.controller;

import com.jessechanrui.template.flowable.flowabletemplate.service.FlowableService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.flowable.task.api.Task;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenrui
 * @version 1.0
 * @description FlowableController
 * @date 2025/8/5
 */
@Tag(name = "流程管理", description = "工作流相关操作API")
@RestController
@RequestMapping("/flowable")
public class FlowableController {

    @Resource
    private FlowableService flowableService;

    // 部署流程
    @PostMapping("/deploy")
    public String deploy() {
        return flowableService.deployProcess();
    }

    // 启动流程实例
    @PostMapping("/start")
    public String start(@RequestParam String applicant) {
        return flowableService.startProcess(applicant);
    }

    // 查询待办任务
    
    @GetMapping("/tasks/{assignee}")
    public List<Task> getTasks(@PathVariable String assignee) {
        return flowableService.getTodoTasks(assignee);
    }

    // 完成任务
    @PostMapping("/complete/{taskId}")
    public String complete(@PathVariable String taskId) {
        return flowableService.completeTask(taskId);
    }
}


